package cn.enilu.flash.service.blindbox;

import cn.enilu.flash.bean.entity.blindbox.BlindBoxGoods;
import cn.enilu.flash.bean.entity.shop.Goods;
import cn.enilu.flash.bean.vo.blindbox.BlindBoxGoodsUserVO;
import cn.enilu.flash.bean.vo.blindbox.BlindBoxGoodsVO;
import cn.enilu.flash.bean.vo.query.SearchFilter;
import cn.enilu.flash.convert.GiftConvert;
import cn.enilu.flash.dao.blindbox.BlindBoxGoodsRepository;
import cn.enilu.flash.dao.shop.GoodsRepository;
import cn.enilu.flash.service.BaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author HYF
 * @ClassName BlindboxService
 * @date 2022年04月27日 5:08 下午
 */
@Slf4j
@Service
public class BlindboxGoodsService extends BaseService<BlindBoxGoods, Long, BlindBoxGoodsRepository> {
    @Autowired
    private BlindBoxGoodsRepository blindBoxGoodsRepository;
    @Autowired
    private GoodsRepository goodsRepository;
    /**
     * 商品列表
     * @param id
     * @return
     */
    public List<BlindBoxGoodsVO> queryBlindBoxGoodsList(Long id) {
        List<BlindBoxGoods> blindBoxList =  queryAll(SearchFilter.build("blindBoxId",id));
        List<BlindBoxGoodsVO> list = GiftConvert.INSTANCE.convertList(blindBoxList);
        for (BlindBoxGoodsVO blindBoxGoods : list) {
            Optional<Goods> goods = goodsRepository.findById(blindBoxGoods.getGoodsId());
            blindBoxGoods.setGoods(goods.get());
        }
        return list;
    }

}